; first sqrt

(define (my-sqrt x) 
  (sqrt-iter 1.0 x))

(define (sqrt-iter guess x) 
  (if (good-enough? guess x)
    guess
    (sqrt-iter (improve guess x) x)))


(define (good-enough? guess x)
  (< (abs (- (square guess) x)) 0.001))

(define (improve guess x)
  (average (/ x guess) guess))

(define (average x y)
  (/ (+ x y) 2))

(define (square x) (* x x))

; exercise

(define (new-good-enough? guess improved-guess)
  (< (abs (- guess improved-guess)) 0.001))

(define (new-sqrt-iter guess x)
  (if (new-good-enough? guess (improve guess x))
    guess
    (new-sqrt-iter (improve guess x) x)))

(define (new-sqrt x)
  (new-sqrt-iter 1.0 x))

